#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
class Solution {
public:
	string longestCommonPrefix(vector<string>& strs) 
	{
		if (strs.size() == 0)
			return string("");

		size_t ans = strs[0].size();
		for (size_t i=1, si=strs.size(); i<si; ++i)
		{
			size_t j=0, sj=min(ans, min(strs[i].size(), strs[i-1].size()));
			ans = min(ans, sj);
			for (; j<sj; ++j)
			{
				if (strs[i][j] != strs[i-1][j])
				{
					ans = min(ans, j);
					break;
				}
			}
		}
		return strs[0].substr(0, ans);
	}
};
/*
int main()
{
	vector<string> strs;
	strs.push_back("aaabb");
	strs.push_back("aabb");
	strs.push_back("aaaab");
	string ans = Solution().longestCommonPrefix(strs);
	cout << ans << endl;
	return 0;
}
*/